<template>
  <div class="home-wrap">
    <!-- <el-row class="header">
      <div class="last-time">
        <div class="title">上次登陆时间</div>
        <span>2019.01.15 00:00:00</span>
      </div>
      <div class="userInfo">
        <div class="user-title">登录人：</div>
        <div class="user-name">自游君</div>
      </div>
      <div class="more">
        <el-dropdown>
          <span class="el-dropdown-link">
            更多
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item>自游君</el-dropdown-item>
            <el-dropdown-item>自游君</el-dropdown-item>
            <el-dropdown-item>自游君</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-row> -->
    <el-row class="audit">
      <el-row class="audit-left">
        <div class="title">信息审核</div>
        <div class="info-box">
          <router-link class="info-person info-item" tag="div" to="/vip/attestation">
            <div class="info-title">个人认证</div>
            <div class="nums">{{ person }}</div>
          </router-link>
          <router-link class="info-company info-item" tag="div" to="/vip/attestationRecord">
            <div class="info-title">企业认证</div>
            <div class="nums">{{ ent }}</div>
          </router-link>
          <router-link class="info-agency info-item" tag="div" to="/vip/agencyAudit">
            <div class="info-title">代理审核</div>
            <div class="nums">{{ aduit }}</div>
          </router-link>
          <router-link class="info-withdraw info-item" tag="div" to="/withdraw/confirm">
            <div class="info-title">提现审核</div>
            <div class="nums">{{ withdraw }}</div>
          </router-link>
        </div>
      </el-row>
      <el-row class="audit-right">
        <div class="title">总用户数</div>
        <div class="user-nums">{{ user }}</div>
      </el-row>
    </el-row>
    <el-row class="new-info">
      <el-row class="audit-left">
        <div class="title">新增信息</div>
        <div class="info-box">
          <div class="info-person info-item">
            <div class="info-title">租赁信息</div>
            <div class="nums">{{ rent }}</div>
          </div>
          <div class="info-company info-item">
            <div class="info-title">销售信息</div>
            <div class="nums">{{ sell }}</div>
          </div>
          <div class="info-agency info-item">
            <div class="info-title">维修信息</div>
            <div class="nums">{{ maintain }}</div>
          </div>
          <div class="info-withdraw info-item">
            <div class="info-title">举报信息</div>
            <div class="nums">{{ report }}</div>
          </div>
          <div class="info-withdraw info-item">
            <div class="info-title">反馈信息</div>
            <div class="nums">{{ suggest }}</div>
          </div>
        </div>
      </el-row>
    </el-row>
  </div>
</template>
<script>
import { agencyId, adiutEntFind, agencyCity, withDrawList, userFind } from '@/api/user'
import { rentMessage, sellMessage, maintainMessage } from '@/api/message'
import { reportMessage } from '@/api/report'
import { suggestMessage } from '@/api/suggest'
export default {
  name: 'HomeDashboard',
  data() {
    return {
      agencyId: {
        state: 1,
        iDisplayStart: 0,
        iDisplayLength: 10,
        username: '',
        phone: ''
      },
      agency: {
        state: 1,
        iDisplayStart: 0,
        iDisplayLength: 10,
        linkname: '',
        areaname: '',
        phone: ''
      },
      withDraw: {
        status: 1,
        iDisplayStart: 0,
        iDisplayLength: 10,
        username: '',
        phone: '',
        fromtime: '',
        totime: ''
      },
      userFind: {
        phone: '',
        state: '',
        userlevel: '',
        iDisplayStart: 0,
        iDisplayLength: 10,
        username: '',
        recommendid: '',
        recommendphone: '',
        fromtime: '',
        totime: '',
        isagency: ''
      },
      person: 0,
      ent: 0,
      aduit: 0,
      withdraw: 0,
      user: 0,
      rent: 0,
      sell: 0,
      maintain: 0,
      report: 0,
      suggest: 0
    }
  },
  created() {
    this.getlist()
    this.getRent()
    this.getSell()
    this.getMaintain()
    this.getReport()
    this.getSuggest()
  },
  methods: {
    getlist() {
      Promise.all([agencyId({ ...this.agencyId }), adiutEntFind({ ...this.agencyId }), agencyCity({ ...this.agency }), withDrawList({ ...this.withDraw }), userFind({ ...this.userFind })])
        .then((res) => {
          this.person = res[0].total
          this.ent = res[1].total
          this.aduit = res[2].total
          this.withdraw = res[3].total
          this.user = res[4].total
        }).catch((e) => {
          this.$message.error({
            message: '请稍后再试',
            duration: 1000
          })
        })
    },
    getRent() {
      const rent = localStorage.getItem('RENT')
      const iDisplayStart = 0
      const iDisplayLength = 10
      const equtype = ''
      const state = ''
      if (rent) {
        rentMessage(equtype, iDisplayStart, iDisplayLength, state)
          .then((res) => {
            const total = res.total
            this.rent = total - Number(rent)
            localStorage.setItem('RENT', total)
          })
      } else {
        rentMessage(equtype, iDisplayStart, iDisplayLength, state)
          .then((res) => {
            const total = res.total
            this.rent = total
            localStorage.setItem('RENT', total)
          })
      }
    },
    getSell() {
      const sell = localStorage.getItem('SELL')
      const page = 1
      const size = 10
      const enttype = ''
      const state = ''
      if (sell) {
        sellMessage(enttype, page, size, state)
          .then((res) => {
            const total = res.total
            this.sell = total - Number(sell)
            localStorage.setItem('SELL', total)
          })
      } else {
        sellMessage(enttype, page, size, state)
          .then((res) => {
            const total = res.total
            this.sell = total
            localStorage.setItem('SELL', total)
          })
      }
    },
    getMaintain() {
      const maintain = localStorage.getItem('MAINTAIN')
      const page = 1
      const size = 10
      const maintainScope = ''
      const state = ''
      if (maintain) {
        maintainMessage(maintainScope, page, size, state)
          .then((res) => {
            const total = res.total
            this.maintain = total - Number(maintain)
            localStorage.setItem('MAINTAIN', total)
          })
      } else {
        maintainMessage(maintainScope, page, size, state)
          .then((res) => {
            const total = res.total
            this.maintain = total
            localStorage.setItem('MAINTAIN', total)
          })
      }
    },
    getReport() {
      const report = localStorage.getItem('REPORT')
      const iDisplayStart = 0
      const iDisplayLength = 10
      const state = ''
      if (report) {
        reportMessage(state, iDisplayStart, iDisplayLength)
          .then((res) => {
            const total = res.total
            this.report = total - Number(report)
            localStorage.setItem('REPORT', total)
          })
      } else {
        reportMessage(state, iDisplayStart, iDisplayLength)
          .then((res) => {
            const total = res.total
            this.report = total
            localStorage.setItem('REPORT', total)
          })
      }
    },
    getSuggest() {
      const suggest = localStorage.getItem('SUGGEST')
      const iDisplayStart = 0
      const iDisplayLength = 10
      const state = ''
      if (suggest) {
        suggestMessage(state, iDisplayStart, iDisplayLength)
          .then((res) => {
            const total = res.total
            this.suggest = total - Number(suggest)
            localStorage.setItem('SUGGEST', total)
          })
      } else {
        suggestMessage(state, iDisplayStart, iDisplayLength)
          .then((res) => {
            const total = res.total
            this.suggest = total
            localStorage.setItem('SUGGEST', total)
          })
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.home-wrap {
  width: 100%;
  padding: 20px;
  box-sizing: border-box;
  .header {
    border: 1px solid #e6e6e6;
    height: 80px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    padding: 0 50px;
    box-sizing: border-box;
    margin-bottom: 20px;
    .last-time {
      display: flex;
      align-items: center;
      height: 100%;
      span {
        margin-left: 20px;
      }
    }
    .userInfo {
      display: flex;
      height: 100%;
      align-items: center;
      margin-left: 50px;
    }
    .more {
      position: absolute;
      width: 100px;
      height: 100%;
      text-align: center;
      line-height: 80px;
      top: 50%;
      right: 0;
      transform: translateY(-50%);
      color: #757575;
      cursor: pointer;
      span {
        width: 100px;
        height: 100%;
        text-align: center;
        line-height: 80px;
        display: block;
      }
    }
  }
  .audit,.new-info{
    height: 150px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    .audit-left {
      width: 90%;
      border: 1px solid #e6e6e6;
      height: 100%;
      background-color: #fff;
      margin-right: 20px;
      padding: 20px;
      box-sizing: border-box;
      display: flex;
      flex-direction: column;
      .title{
        margin-bottom: 15px;
      }
      .info-box {
        width: 100%;
        display: flex;
        justify-content: space-between;
        .info-item{
          flex: 1;
          height: 100%;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          cursor: pointer;
          .info-title {
            font-weight: 700;
            margin-bottom: 30px;
          }
        }
      }
    }
    .audit-right {
      width: calc(100% - 90% - 20px);
      border: 1px solid #e6e6e6;
      height: 100%;
      background-color: #2C363B;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      .title{
        color: #fff;
        margin-bottom: 10px;
      }
      .user-nums {
        color: #F48000;
      }
    }
  }
  .new-info{
    .audit-left{
      width: 100%;
      margin-right: 0;
    }
  }
}
</style>
